﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Public;
using BUL;

namespace Presentation
{
    public partial class frmMain : Form
    {
        User userCms = new User();
        AdvertisementBUL advertisement = new AdvertisementBUL();
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            // set fix = 2 (Storekeeper)
            //userCms.Role.RoleId = 1;
            //updateAdvertedProduct();
        }
        public void updateAdvertedProduct()
        {
            if (userCms.Role.RoleId == 1)
            {
                string today = DateTime.Now.ToString("yyyy-MM-dd");
                DataTable dtstartDate = advertisement.checkTodayFrom(today);
                if (dtstartDate.Rows.Count > 0)
                {
                    for (int i = 0; i < dtstartDate.Rows.Count; i++)
                    {
                        int advertId = int.Parse(dtstartDate.Rows[i][0].ToString());
                        DataTable apdt = advertisement.getAdvertedProduct(advertId);
                        if (apdt.Rows.Count > 0)
                        {
                            for (int j = 0; j < apdt.Rows.Count; j++)
                            {
                                Product product = new Product();
                                float saleOff = float.Parse(apdt.Rows[i][2].ToString());
                                float updatedWorth = (100 - saleOff) / 100;
                                product.ProductId = int.Parse(apdt.Rows[i][1].ToString());
                                product.Worth = updatedWorth;
                                advertisement.updateWorth(product);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("This bar code can be used.", "Notice",
                       MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        private void changePasswordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmChangePassword frmChangePassword = new frmChangePassword();
            //frmChangePassword.Show();

        }

        private void staffToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageStaff frmManageStaff = new frmManageStaff();
            frmManageStaff.Show();
            this.Hide();
        }

        private void batchToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageDataStore frmManageDS = new frmManageDataStore();
            frmManageDS.Show();
            this.Hide();
        }

        private void hToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageBatch frmManageBatch = new frmManageBatch();
            frmManageBatch.Show();
            this.Hide();
        }

        private void productToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmManageProduct frmManageProduct = new frmManageProduct();
            frmManageProduct.Show();
            this.Hide();
        }

        private void advertisementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAdvertisement frmAdvert = new frmAdvertisement();
            frmAdvert.Show();
            this.Hide();
        }

        private void loyaltyCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmLoyaltyCard frmLC = new frmLoyaltyCard();
            frmLC.Show();
            this.Hide();
        }

        private void paymentTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmPaymentTransaction frmPT = new frmPaymentTransaction();
            frmPT.Show();
            this.Hide();
        }

        private void notificationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmNotification frmNotice = new frmNotification();
            frmNotice.Show();
            this.Hide();
        }


    }
}
